package Dinamica;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Tornato {

	/**
	 * @param args
	 */
	
	public static int[] postes = new int[5001];

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String linea = bf.readLine();
		while(linea != null){
				int m=Integer.parseInt(linea);		 
				if(m!=0){
					
					int k=0;
					linea = bf.readLine();
					int n = 0;
					int res = 0;
					for(int i=0; i<linea.length(); i=i+4){
						postes[n] = Integer.parseInt(linea.charAt(i)+"");
						n++; 
						if(m%2==0){
							postes[n] = Integer.parseInt(linea.charAt(i+2)+"");
						}
						n++; 
						if(postes[k]==0 && postes[k+1]==0){postes[k+1] = 1; res++; }
						k++;
					}
					if(postes[k]==0 && postes[k+1]==0){postes[k+1] = 1; res++; }
					k++;
					if(postes[k]==0 && postes[k+1]==0){postes[k+1] = 1; res++; }
					System.out.println(res);
					
					if(!bf.ready()) break;
					linea = bf.readLine();
				}
				
				
			
		}
	}
	


}
